{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# API 文档介绍（Azure API）\n",
    "* 本周主要内容：API文档阅读介绍及计算机视觉入门（认知服务）\n",
    "* 20春_API_人工智能与机器学习_week02\n",
    "*  电子讲义设计者：许智超，廖汉腾\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "![app_交互设计](https://pic2.zhimg.com/v2-6c478325d02ca3363ec1817a952d5321_r.jpg)\n",
    "\n",
    "-----\n",
    "![app_API_交互设计](http://coverall1.splunk.com/web_assets/developers/devguide/Essentials02_Splunk_app_architecture.png)\n",
    "\n",
    "## 复习\n",
    "\n",
    "复习1：上周内容，AI、API、机器学习的基本认知以及数据科学的基本流程  \n",
    "\n",
    "* 1、API for AI 有哪些人工智能的分类（计算机视觉、语义识别、自然语言处理、推荐系统）\n",
    "* 2、机器学习的关键输入是什么？（有一定规范的数据）\n",
    "* 3、数据科学的基本流程（四个循环环节:问题定义->ETL和特征值提取->学习（机器）->模型部署）\n",
    "\n",
    "复习2：jupyter的基本使用，json、requests  主要包括以下内容可能涉及的API操作：\n",
    "\n",
    "* 1、requests POST传递参数 的基础用法\n",
    "* 2、JSON 格式的基本转换（字典）\n",
    "* 3、字典的处理，pandas转化数据结构\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "\n",
    "-----\n",
    "\n",
    "![Face_识别示例](http://q7rdfqeve.bkt.clouddn.com/Azure_img.jpg)\n",
    "\n",
    "\n",
    "## 本周内容及学习目标\n",
    "\n",
    "本周内容聚集在复习1中的计算机视觉，以及复习2中的API操作部分，学习解决一下挑战：\n",
    "\n",
    "1. 尝试操作计算机视觉人脸识别返回[人脸识别效果](https://azure.microsoft.com/zh-cn/services/cognitive-services/face/)\n",
    "2. 阅读Azure计算机视觉的[人脸文档](https://docs.microsoft.com/zh-cn/azure/cognitive-services/face/)，以及[人脸 API v1.0文档](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236)\n",
    "2. 观看影片[知智1分钟计算机视觉](https://zhuanlan.zhihu.com/p/35652529) 与[知智1分钟人脸识别](https://zhuanlan.zhihu.com/p/36262110)\n",
    "3. 注册Azure 使用API免费服务，获取key以为获取API应用做准备\n",
    "4. 使用requests，用代码取得API回复\n",
    "5. 写出代码，实现输入一个图片URL，可以识别出每个人脸的年龄、性别、眼镜的，加总成绩1分；列出每个人最可能的3种情绪及其判别值再加1分。\n",
    "6. 使用pandas 将返回数据用数据框展示出来。\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "/* 本电子讲义使用之CSS */\n",
       "div.code_cell {\n",
       "    background-color: #e5f1fe;\n",
       "}\n",
       "div.cell.selected {\n",
       "    background-color: #effee2;\n",
       "    font-size: 2rem;\n",
       "    line-height: 2.4rem;\n",
       "}\n",
       "div.cell.selected .rendered_html table {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html pre code {\n",
       "    background-color: #C4E4ff;   \n",
       "    padding: 2px 25px;\n",
       "}\n",
       ".rendered_html pre {\n",
       "    background-color: #99c9ff;\n",
       "}\n",
       "div.code_cell .CodeMirror {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html img, .rendered_html svg {\n",
       "    max-width: 50%;\n",
       "    height: auto;\n",
       "    float: center;\n",
       "}\n",
       "/* Gradient transparent - color - transparent */\n",
       "hr {\n",
       "    border: 0;\n",
       "    border-bottom: 1px dashed #ccc;\n",
       "}\n",
       ".emoticon{\n",
       "    font-size: 5rem;\n",
       "    line-height: 4.4rem;\n",
       "    text-align: center;\n",
       "    vertical-align: middle;\n",
       "}\n",
       "\n",
       "</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "/* 本电子讲义使用之CSS */\n",
    "div.code_cell {\n",
    "    background-color: #e5f1fe;\n",
    "}\n",
    "div.cell.selected {\n",
    "    background-color: #effee2;\n",
    "    font-size: 2rem;\n",
    "    line-height: 2.4rem;\n",
    "}\n",
    "div.cell.selected .rendered_html table {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html pre code {\n",
    "    background-color: #C4E4ff;   \n",
    "    padding: 2px 25px;\n",
    "}\n",
    ".rendered_html pre {\n",
    "    background-color: #99c9ff;\n",
    "}\n",
    "div.code_cell .CodeMirror {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html img, .rendered_html svg {\n",
    "    max-width: 50%;\n",
    "    height: auto;\n",
    "    float: center;\n",
    "}\n",
    "/* Gradient transparent - color - transparent */\n",
    "hr {\n",
    "    border: 0;\n",
    "    border-bottom: 1px dashed #ccc;\n",
    "}\n",
    ".emoticon{\n",
    "    font-size: 5rem;\n",
    "    line-height: 4.4rem;\n",
    "    text-align: center;\n",
    "    vertical-align: middle;\n",
    "}\n",
    "\n",
    "</style>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "body {\n",
       "    margin: 0 auto;\n",
       "    font-family: \"Microsoft YaHei\", arial,sans-serif;\n",
       "    color: #444444;\n",
       "    line-height: 1;\n",
       "    padding: 30px;\n",
       "}\n",
       "@media screen and (min-width: 768px) {\n",
       "    body {\n",
       "        width: 748px;\n",
       "        margin: 10px auto;\n",
       "    }\n",
       "}\n",
       "h1, h2, h3, h4 {\n",
       "    color: #111111;\n",
       "    font-weight: 400;\n",
       "    margin-top: 1em;\n",
       "}\n",
       "\n",
       "h1, h2, h3, h4, h5 {\n",
       "\tfont-family: Georgia, Palatino, serif;\n",
       "}\n",
       "h1, h2, h3, h4, h5, p , dl{\n",
       "    margin-bottom: 16px;\n",
       "    padding: 0;\n",
       "}\n",
       "h1 {\n",
       "    font-size: 48px;\n",
       "    line-height: 54px;\n",
       "}\n",
       "h2 {\n",
       "    font-size: 36px;\n",
       "    line-height: 42px;\n",
       "}\n",
       "h1, h2 {\n",
       "    border-bottom: 1px solid #EFEAEA;\n",
       "    padding-bottom: 10px;\n",
       "}\n",
       "h3 {\n",
       "    font-size: 24px;\n",
       "    line-height: 30px;\n",
       "}\n",
       "h4 {\n",
       "    font-size: 21px;\n",
       "    line-height: 26px;\n",
       "}\n",
       "h5 {\n",
       "    font-size: 18px;\n",
       "    list-style: 23px;\n",
       "}\n",
       "a {\n",
       "    color: #0099ff;\n",
       "    margin: 0;\n",
       "    padding: 0;\n",
       "    vertical-align: baseline;\n",
       "}\n",
       "a:hover {\n",
       "    text-decoration: none;\n",
       "    color: #ff6600;\n",
       "}\n",
       "a:visited {\n",
       "    /*color: purple;*/\n",
       "}\n",
       "ul, ol {\n",
       "    padding: 0;\n",
       "    padding-left: 24px;\n",
       "    margin: 0;\n",
       "}\n",
       "li {\n",
       "    line-height: 24px;\n",
       "}\n",
       "p, ul, ol {\n",
       "    font-size: 16px;\n",
       "    line-height: 24px;\n",
       "}\n",
       "\n",
       "ol ol, ul ol {\n",
       "    list-style-type: lower-roman;\n",
       "}\n",
       "\n",
       "/*pre {\n",
       "    padding: 0px 24px;\n",
       "    max-width: 800px;\n",
       "    white-space: pre-wrap;\n",
       "}\n",
       "code {\n",
       "    font-family: Consolas, Monaco, Andale Mono, monospace;\n",
       "    line-height: 1.5;\n",
       "    font-size: 13px;\n",
       "}*/\n",
       "\n",
       "code, pre {\n",
       "    border-radius: 3px;\n",
       "    background-color:#f7f7f7;\n",
       "    color: inherit;\n",
       "}\n",
       "\n",
       "code {\n",
       "    font-family: Consolas, Monaco, Andale Mono, monospace;\n",
       "    margin: 0 2px;\n",
       "}\n",
       "\n",
       "pre {\n",
       "    line-height: 1.7em;\n",
       "    overflow: auto;\n",
       "    padding: 6px 10px;\n",
       "    border-left: 5px solid #6CE26C;\n",
       "}\n",
       "\n",
       "pre > code {\n",
       "    border: 0;\n",
       "    display: inline;\n",
       "    max-width: initial;\n",
       "    padding: 0;\n",
       "    margin: 0;\n",
       "    overflow: initial;\n",
       "    line-height: inherit;\n",
       "    font-size: .85em;\n",
       "    white-space: pre;\n",
       "    background: 0 0;\n",
       "\n",
       "}\n",
       "\n",
       "code {\n",
       "    color: #666555;\n",
       "}\n",
       "\n",
       "\n",
       "/** markdown preview plus 对于代码块的处理有些问题, 所以使用统一的颜色 */\n",
       "/*code .keyword {\n",
       "  color: #8959a8;\n",
       "}\n",
       "\n",
       "code .number {\n",
       "  color: #f5871f;\n",
       "}\n",
       "\n",
       "code .comment {\n",
       "  color: #998\n",
       "}*/\n",
       "\n",
       "aside {\n",
       "    display: block;\n",
       "    float: right;\n",
       "    width: 390px;\n",
       "}\n",
       "blockquote {\n",
       "    border-left:.5em solid #eee;\n",
       "    padding: 0 0 0 2em;\n",
       "    margin-left:0;\n",
       "}\n",
       "blockquote  cite {\n",
       "    font-size:14px;\n",
       "    line-height:20px;\n",
       "    color:#bfbfbf;\n",
       "}\n",
       "blockquote cite:before {\n",
       "    content: '\\2014 \\00A0';\n",
       "}\n",
       "\n",
       "blockquote p {\n",
       "    color: #666;\n",
       "}\n",
       "hr {\n",
       "    text-align: left;\n",
       "    color: #999;\n",
       "    height: 2px;\n",
       "    padding: 0;\n",
       "    margin: 16px 0;\n",
       "    background-color: #e7e7e7;\n",
       "    border: 0 none;\n",
       "}\n",
       "\n",
       "dl {\n",
       "    padding: 0;\n",
       "}\n",
       "\n",
       "dl dt {\n",
       "    padding: 10px 0;\n",
       "    margin-top: 16px;\n",
       "    font-size: 1em;\n",
       "    font-style: italic;\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "dl dd {\n",
       "    padding: 0 16px;\n",
       "    margin-bottom: 16px;\n",
       "}\n",
       "\n",
       "dd {\n",
       "    margin-left: 0;\n",
       "}\n",
       "\n",
       "/* Code below this line is copyright Twitter Inc. */\n",
       "\n",
       "button,\n",
       "input,\n",
       "select,\n",
       "textarea {\n",
       "    font-size: 100%;\n",
       "    margin: 0;\n",
       "    vertical-align: baseline;\n",
       "    *vertical-align: middle;\n",
       "}\n",
       "button, input {\n",
       "    line-height: normal;\n",
       "    *overflow: visible;\n",
       "}\n",
       "button::-moz-focus-inner, input::-moz-focus-inner {\n",
       "    border: 0;\n",
       "    padding: 0;\n",
       "}\n",
       "button,\n",
       "input[type=\"button\"],\n",
       "input[type=\"reset\"],\n",
       "input[type=\"submit\"] {\n",
       "    cursor: pointer;\n",
       "    -webkit-appearance: button;\n",
       "}\n",
       "input[type=checkbox], input[type=radio] {\n",
       "    cursor: pointer;\n",
       "}\n",
       "/* override default chrome & firefox settings */\n",
       "input:not([type=\"image\"]), textarea {\n",
       "    -webkit-box-sizing: content-box;\n",
       "    -moz-box-sizing: content-box;\n",
       "    box-sizing: content-box;\n",
       "}\n",
       "\n",
       "input[type=\"search\"] {\n",
       "    -webkit-appearance: textfield;\n",
       "    -webkit-box-sizing: content-box;\n",
       "    -moz-box-sizing: content-box;\n",
       "    box-sizing: content-box;\n",
       "}\n",
       "input[type=\"search\"]::-webkit-search-decoration {\n",
       "    -webkit-appearance: none;\n",
       "}\n",
       "label,\n",
       "input,\n",
       "select,\n",
       "textarea {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 13px;\n",
       "    font-weight: normal;\n",
       "    line-height: normal;\n",
       "    margin-bottom: 18px;\n",
       "}\n",
       "input[type=checkbox], input[type=radio] {\n",
       "    cursor: pointer;\n",
       "    margin-bottom: 0;\n",
       "}\n",
       "input[type=text],\n",
       "input[type=password],\n",
       "textarea,\n",
       "select {\n",
       "    display: inline-block;\n",
       "    width: 210px;\n",
       "    padding: 4px;\n",
       "    font-size: 13px;\n",
       "    font-weight: normal;\n",
       "    line-height: 18px;\n",
       "    height: 18px;\n",
       "    color: #808080;\n",
       "    border: 1px solid #ccc;\n",
       "    -webkit-border-radius: 3px;\n",
       "    -moz-border-radius: 3px;\n",
       "    border-radius: 3px;\n",
       "}\n",
       "select, input[type=file] {\n",
       "    height: 27px;\n",
       "    line-height: 27px;\n",
       "}\n",
       "textarea {\n",
       "    height: auto;\n",
       "}\n",
       "/* grey out placeholders */\n",
       ":-moz-placeholder {\n",
       "    color: #bfbfbf;\n",
       "}\n",
       "::-webkit-input-placeholder {\n",
       "    color: #bfbfbf;\n",
       "}\n",
       "input[type=text],\n",
       "input[type=password],\n",
       "select,\n",
       "textarea {\n",
       "    -webkit-transition: border linear 0.2s, box-shadow linear 0.2s;\n",
       "    -moz-transition: border linear 0.2s, box-shadow linear 0.2s;\n",
       "    transition: border linear 0.2s, box-shadow linear 0.2s;\n",
       "    -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);\n",
       "    -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);\n",
       "    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);\n",
       "}\n",
       "input[type=text]:focus, input[type=password]:focus, textarea:focus {\n",
       "    outline: none;\n",
       "    border-color: rgba(82, 168, 236, 0.8);\n",
       "    -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6);\n",
       "    -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6);\n",
       "    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6);\n",
       "}\n",
       "/* buttons */\n",
       "button {\n",
       "    display: inline-block;\n",
       "    padding: 4px 14px;\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 13px;\n",
       "    line-height: 18px;\n",
       "    -webkit-border-radius: 4px;\n",
       "    -moz-border-radius: 4px;\n",
       "    border-radius: 4px;\n",
       "    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "    -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "    background-color: #0064cd;\n",
       "    background-repeat: repeat-x;\n",
       "    background-image: -khtml-gradient(linear, left top, left bottom, from(#049cdb), to(#0064cd));\n",
       "    background-image: -moz-linear-gradient(top, #049cdb, #0064cd);\n",
       "    background-image: -ms-linear-gradient(top, #049cdb, #0064cd);\n",
       "    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #049cdb), color-stop(100%, #0064cd));\n",
       "    background-image: -webkit-linear-gradient(top, #049cdb, #0064cd);\n",
       "    background-image: -o-linear-gradient(top, #049cdb, #0064cd);\n",
       "    background-image: linear-gradient(top, #049cdb, #0064cd);\n",
       "    color: #fff;\n",
       "    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);\n",
       "    border: 1px solid #004b9a;\n",
       "    border-bottom-color: #003f81;\n",
       "    -webkit-transition: 0.1s linear all;\n",
       "    -moz-transition: 0.1s linear all;\n",
       "    transition: 0.1s linear all;\n",
       "    border-color: #0064cd #0064cd #003f81;\n",
       "    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);\n",
       "}\n",
       "button:hover {\n",
       "    color: #fff;\n",
       "    background-position: 0 -15px;\n",
       "    text-decoration: none;\n",
       "}\n",
       "button:active {\n",
       "    -webkit-box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "    -moz-box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "    box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);\n",
       "}\n",
       "button::-moz-focus-inner {\n",
       "    padding: 0;\n",
       "    border: 0;\n",
       "}\n",
       "table {\n",
       "    *border-collapse: collapse; /* IE7 and lower */\n",
       "    border-spacing: 0;\n",
       "    width: 100%;\n",
       "}\n",
       "table {\n",
       "    border: solid #ccc 1px;\n",
       "    -moz-border-radius: 6px;\n",
       "    -webkit-border-radius: 6px;\n",
       "    border-radius: 6px;\n",
       "    /*-webkit-box-shadow: 0 1px 1px #ccc;\n",
       "    -moz-box-shadow: 0 1px 1px #ccc;\n",
       "    box-shadow: 0 1px 1px #ccc;   */\n",
       "}\n",
       "table tr:hover {\n",
       "    background: #fbf8e9;\n",
       "    -o-transition: all 0.1s ease-in-out;\n",
       "    -webkit-transition: all 0.1s ease-in-out;\n",
       "    -moz-transition: all 0.1s ease-in-out;\n",
       "    -ms-transition: all 0.1s ease-in-out;\n",
       "    transition: all 0.1s ease-in-out;\n",
       "}\n",
       "table td, .table th {\n",
       "    border-left: 1px solid #ccc;\n",
       "    border-top: 1px solid #ccc;\n",
       "    padding: 10px;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table th {\n",
       "    background-color: #dce9f9;\n",
       "    background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));\n",
       "    background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);\n",
       "    background-image:    -moz-linear-gradient(top, #ebf3fc, #dce9f9);\n",
       "    background-image:     -ms-linear-gradient(top, #ebf3fc, #dce9f9);\n",
       "    background-image:      -o-linear-gradient(top, #ebf3fc, #dce9f9);\n",
       "    background-image:         linear-gradient(top, #ebf3fc, #dce9f9);\n",
       "    /*-webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;\n",
       "    -moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;\n",
       "    box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;*/\n",
       "    border-top: none;\n",
       "    text-shadow: 0 1px 0 rgba(255,255,255,.5);\n",
       "    padding: 5px;\n",
       "}\n",
       "\n",
       "table td:first-child, table th:first-child {\n",
       "    border-left: none;\n",
       "}\n",
       "\n",
       "table th:first-child {\n",
       "    -moz-border-radius: 6px 0 0 0;\n",
       "    -webkit-border-radius: 6px 0 0 0;\n",
       "    border-radius: 6px 0 0 0;\n",
       "}\n",
       "table th:last-child {\n",
       "    -moz-border-radius: 0 6px 0 0;\n",
       "    -webkit-border-radius: 0 6px 0 0;\n",
       "    border-radius: 0 6px 0 0;\n",
       "}\n",
       "table th:only-child{\n",
       "    -moz-border-radius: 6px 6px 0 0;\n",
       "    -webkit-border-radius: 6px 6px 0 0;\n",
       "    border-radius: 6px 6px 0 0;\n",
       "}\n",
       "table tr:last-child td:first-child {\n",
       "    -moz-border-radius: 0 0 0 6px;\n",
       "    -webkit-border-radius: 0 0 0 6px;\n",
       "    border-radius: 0 0 0 6px;\n",
       "}\n",
       "table tr:last-child td:last-child {\n",
       "    -moz-border-radius: 0 0 6px 0;\n",
       "    -webkit-border-radius: 0 0 6px 0;\n",
       "    border-radius: 0 0 6px 0;\n",
       "}\n",
       "<style>                                            "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 教不完所有API，但可以学如何读、用API文件\n",
    "\n",
    "## Review: URLs for API documentation\n",
    "\n",
    "* Symbol ? 标记\n",
    "* Base url 目标API的url\n",
    "* Directories 目录, 功能\n",
    "    * [face++ detect API](https://console.faceplusplus.com.cn/documents/4888373) \n",
    "        * [https://api-cn.faceplusplus.com/facepp/v3/detect?](https://api-cn.faceplusplus.com/facepp/v3/detect)\n",
    "    * [搜索POI](https://lbs.amap.com/api/webservice/guide/api/search)\n",
    "        * [https://restapi.amap.com/v3/place/text?parameters](https://restapi.amap.com/v3/place/text?parameters)\n",
    "    * [行政区域查询](https://lbs.amap.com/api/webservice/guide/api/district)\n",
    "        * [https://restapi.amap.com/v3/config/district?parameters](https://restapi.amap.com/v3/config/district?parameters)\n",
    "       "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Review: APIs use HTTP, HTTP requests的不同模式\n",
    "\n",
    "* GET\n",
    "* POST\n",
    "* (optional) DELETE\n",
    "* e.g\n",
    "    * [https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236)\n",
    "\n",
    "\n",
    "![Requests](http://cn.python-requests.org/zh_CN/latest/_static/requests-sidebar.png)\n",
    "\n",
    "----\n",
    "\n",
    "\n",
    "request复习\n",
    "\n",
    "* [http://cn.python-requests.org/zh_CN/latest/](http://cn.python-requests.org/zh_CN/latest/)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 如果有SDK (Software Developent Kit)--> 不用自己叫HTTP requests\n",
    "\n",
    "* [Azure API for Cognitive-Face-Python](https://docs.microsoft.com/zh-cn/azure/cognitive-services/face/quickstarts/python-sdk)\n",
    "* 好处: 不用HTTP requests代码\n",
    "* 难点: SDK可能需要阅读另外的文档來叫用。若沒有SDK文档，你要自己看懂代碼"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 如果不想用，我们还是应该自己学会如何叫HTTP requests\n",
    "\n",
    "* img_url  \n",
    "\n",
    "http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg\n",
    "\n",
    "![http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg](http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 参考API文档\n",
    "\n",
    "* [Face API - v1.0](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524c)\n",
    "\n",
    "* [API URL format]\n",
    "    * Request URL [https://[location].api.cognitive.microsoft.com/face/v1.0/detect[?returnFaceId][&returnFaceLandmarks][&returnFaceAttributes]](https://[location].api.cognitive.microsoft.com/face/v1.0/detect[?returnFaceId][&returnFaceLandmarks][&returnFaceAttributes)\n",
    "    * symbol ?\n",
    "    * [location]\n",
    "    * base url  [https://[location].api.cognitive.microsoft.com/face/v1.0/detect](https://[location].api.cognitive.microsoft.com/face/v1.0/detect)\n",
    "    \n",
    "## Python Code sample\n",
    "\n",
    "\n",
    "请大家在Azure网站上面找到这两部分内容~我会找同学分享屏幕展示\n",
    "\n",
    "\n",
    "```python\n",
    "\n",
    "########### Python 3.2 #############\n",
    "import http.client, urllib.request, urllib.parse, urllib.error, base64\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': '{subscription key}',\n",
    "}\n",
    "\n",
    "params = urllib.parse.urlencode({\n",
    "    # Request parameters\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    'returnFaceAttributes': '{string}',\n",
    "})\n",
    "\n",
    "try:\n",
    "    conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')\n",
    "    conn.request(\"POST\", \"/face/v1.0/detect?%s\" % params, \"{body}\", headers)\n",
    "    response = conn.getresponse()\n",
    "    data = response.read()\n",
    "    print(data)\n",
    "    conn.close()\n",
    "except Exception as e:\n",
    "    print(\"[Errno {0}] {1}\".format(e.errno, e.strerror))\n",
    "\n",
    "```\n",
    "----\n",
    "\n",
    "```python\n",
    "\n",
    "import requests\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "subscription_key = None\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://<My Endpoint String>.com/face/v1.0/detect'\n",
    "\n",
    "image_url = 'https://upload.wikimedia.org/wikipedia/commons/3/37/Dagestani_man_and_woman.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "print(json.dumps(response.json()))\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 1、导入需要的requests模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 先导入为们需要的模块\n",
    "import requests"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 2、输入我们需要API网站注册的API_Key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "KEY = 'YOUR KEY'  # Replace with a valid Subscription Key here.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 3、目标url [base url] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Base URL,  Request URL中 符号?以前\n",
    "BASE_URL = 'https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect' \n",
    "\n",
    "# API KEY 不要用別人的\n",
    "KEY = 'YOUR KEY'  # Replace with a valid Subscription Key here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 4、沿用API文档的示范代码,准备我们的headers和图片(数据)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 沿用API的示范代碼，{subscription key}用KEY代入\n",
    "HEADERS = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': '{}'.format(KEY),\n",
    "}\n",
    "\n",
    "img_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 5、准备symbol ? 后面的数据,这里需要注意,一定要详细阅读API文档中的 “参数功能”,按照要求格式准备payload\n",
    "\n",
    "* 参数功能可能有:\n",
    "    * 1、是否必要?必要的一定要准备好\n",
    "    * 2、选填的一定是功能,要根据功能需求 好好填噢"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {\n",
    "    'url': '{}'.format(img_url),\n",
    "}\n",
    "payload = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'flase',\n",
    "    'returnFaceAttributes': '{}'.format('age,gender,glasses'), \n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 6、requests发送我们请求\n",
    "\n",
    "* 注意:\n",
    "    * 详细阅读文档,注意请求方式(GET、POST、DELETE)\n",
    "    * 注意json 和字典的差异 ,str vs dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 坑。参考http://docs.python-requests.org/zh_CN/latest/user/quickstart.html  【更加复杂的post请求】\n",
    "# 差別是 string 字串 vs. dict 字典\n",
    "# Azura 使用的是 data = json.dumps(payload) 或 json=payload，data = payload 会出错\n",
    "r = requests.post(BASE_URL, data=json.dumps(data), params=payload, headers=HEADERS)\n",
    "\n",
    "r.status_code\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 拿到数据会不会很开心? 不过我们还可以做的更好\n",
    "* 别忘记我们是会基本处理数据的,至少要想到用pandas表格化数据."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 由于我Azure免费已过期，无法给大家展示Azure，我将用face++用同样的6个步骤给大家展示\n",
    "#  face++ Detect API(面部检测) 示范6个步骤\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'{\"request_id\":\"1585210646,b524119b-7450-4ba9-80bd-3224202bbee0\",\"time_used\":317,\"faces\":[{\"face_token\":\"7259aebcf1102e77d319afb93421b20a\",\"face_rectangle\":{\"top\":123,\"left\":138,\"width\":90,\"height\":90},\"attributes\":{\"gender\":{\"value\":\"Male\"},\"age\":{\"value\":23},\"smile\":{\"value\":99.995,\"threshold\":50.000},\"emotion\":{\"anger\":0.059,\"disgust\":0.059,\"fear\":0.059,\"happiness\":42.294,\"neutral\":52.431,\"sadness\":4.920,\"surprise\":0.179}}},{\"face_token\":\"6406687a3bddb21f8f578f71824bde69\",\"face_rectangle\":{\"top\":122,\"left\":373,\"width\":65,\"height\":65},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":37},\"smile\":{\"value\":98.866,\"threshold\":50.000},\"emotion\":{\"anger\":0.169,\"disgust\":7.280,\"fear\":0.138,\"happiness\":17.689,\"neutral\":8.067,\"sadness\":66.519,\"surprise\":0.138}}},{\"face_token\":\"6bd9235ff544c5971a9f6ae32e6928e6\",\"face_rectangle\":{\"top\":46,\"left\":675,\"width\":54,\"height\":54},\"attributes\":{\"gender\":{\"value\":\"Male\"},\"age\":{\"value\":23},\"smile\":{\"value\":100.000,\"threshold\":50.000},\"emotion\":{\"anger\":0.000,\"disgust\":0.000,\"fear\":0.000,\"happiness\":99.996,\"neutral\":0.001,\"sadness\":0.002,\"surprise\":0.001}}},{\"face_token\":\"fab96cc0c923e31011b2017d53874f81\",\"face_rectangle\":{\"top\":98,\"left\":235,\"width\":53,\"height\":53},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":22},\"smile\":{\"value\":99.997,\"threshold\":50.000},\"emotion\":{\"anger\":0.000,\"disgust\":0.001,\"fear\":0.000,\"happiness\":99.990,\"neutral\":0.009,\"sadness\":0.000,\"surprise\":0.000}}},{\"face_token\":\"3d51431ac7243d1bfdfd9ff72eb0dd30\",\"face_rectangle\":{\"top\":75,\"left\":444,\"width\":52,\"height\":52},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":28},\"smile\":{\"value\":99.999,\"threshold\":50.000},\"emotion\":{\"anger\":0.001,\"disgust\":0.001,\"fear\":0.027,\"happiness\":99.933,\"neutral\":0.027,\"sadness\":0.010,\"surprise\":0.001}}},{\"face_token\":\"e00fb75aac6cc7c5f6aa55b17bf8cd76\",\"face_rectangle\":{\"top\":98,\"left\":537,\"width\":48,\"height\":48}}],\"image_id\":\"TfC1AByqtXhfuQ6DruqVww==\",\"face_num\":6}\\n'\n"
     ]
    }
   ],
   "source": [
    "# 1、先导入为们需要的模块\n",
    "import requests\n",
    "\n",
    "\n",
    "api_secret = \"Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3\"\n",
    "# 2、输入我们API_Key\n",
    "api_key = 'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov'  # Replace with a valid Subscription Key here.\n",
    "\n",
    "\n",
    "# 3、目标url\n",
    "# 这里也可以使用本地图片 例如：filepath =\"image/tupian.jpg\"\n",
    "BASE_URL = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "img_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg'\n",
    "\n",
    "# 4、沿用API文档的示范代码,准备我们的headers和图片(数据)\n",
    "\n",
    "headers = {\n",
    "    'Content-Type': 'application/json',\n",
    "}\n",
    "\n",
    "# 5、准备symbol ? 后面的数据\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,smiling,emotion', \n",
    "}\n",
    "\n",
    "#  6、requests发送我们请求\n",
    "r = requests.post(BASE_URL, params=payload, headers=headers)\n",
    "\n",
    "r.status_code\n",
    "print(r.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1585210646,b524119b-7450-4ba9-80bd-3224202bbee0',\n",
       " 'time_used': 317,\n",
       " 'faces': [{'face_token': '7259aebcf1102e77d319afb93421b20a',\n",
       "   'face_rectangle': {'top': 123, 'left': 138, 'width': 90, 'height': 90},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 23},\n",
       "    'smile': {'value': 99.995, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.059,\n",
       "     'disgust': 0.059,\n",
       "     'fear': 0.059,\n",
       "     'happiness': 42.294,\n",
       "     'neutral': 52.431,\n",
       "     'sadness': 4.92,\n",
       "     'surprise': 0.179}}},\n",
       "  {'face_token': '6406687a3bddb21f8f578f71824bde69',\n",
       "   'face_rectangle': {'top': 122, 'left': 373, 'width': 65, 'height': 65},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 37},\n",
       "    'smile': {'value': 98.866, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.169,\n",
       "     'disgust': 7.28,\n",
       "     'fear': 0.138,\n",
       "     'happiness': 17.689,\n",
       "     'neutral': 8.067,\n",
       "     'sadness': 66.519,\n",
       "     'surprise': 0.138}}},\n",
       "  {'face_token': '6bd9235ff544c5971a9f6ae32e6928e6',\n",
       "   'face_rectangle': {'top': 46, 'left': 675, 'width': 54, 'height': 54},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 23},\n",
       "    'smile': {'value': 100.0, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.0,\n",
       "     'disgust': 0.0,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 99.996,\n",
       "     'neutral': 0.001,\n",
       "     'sadness': 0.002,\n",
       "     'surprise': 0.001}}},\n",
       "  {'face_token': 'fab96cc0c923e31011b2017d53874f81',\n",
       "   'face_rectangle': {'top': 98, 'left': 235, 'width': 53, 'height': 53},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 22},\n",
       "    'smile': {'value': 99.997, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.0,\n",
       "     'disgust': 0.001,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 99.99,\n",
       "     'neutral': 0.009,\n",
       "     'sadness': 0.0,\n",
       "     'surprise': 0.0}}},\n",
       "  {'face_token': '3d51431ac7243d1bfdfd9ff72eb0dd30',\n",
       "   'face_rectangle': {'top': 75, 'left': 444, 'width': 52, 'height': 52},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 28},\n",
       "    'smile': {'value': 99.999, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.001,\n",
       "     'disgust': 0.001,\n",
       "     'fear': 0.027,\n",
       "     'happiness': 99.933,\n",
       "     'neutral': 0.027,\n",
       "     'sadness': 0.01,\n",
       "     'surprise': 0.001}}},\n",
       "  {'face_token': 'e00fb75aac6cc7c5f6aa55b17bf8cd76',\n",
       "   'face_rectangle': {'top': 98, 'left': 537, 'width': 48, 'height': 48}}],\n",
       " 'image_id': 'TfC1AByqtXhfuQ6DruqVww==',\n",
       " 'face_num': 6}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = r.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 要如何简化此数据方便使用?\n",
    "* pandas !!\n",
    "* json_normalize：\n",
    "    * [json_normalize github](https://github.com/pandas-dev/pandas/blob/v1.0.3/pandas/io/json/_normalize.py#L114-L358)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  face_rectangle (json_normalize方法) pandas黑魔法\n",
    "* 先针对这变量看观察"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "# from pandas.io.json import json_normalize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# results['faces']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "df = pd.json_normalize(results,record_path='faces')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <th>attributes.age.value</th>\n",
       "      <th>attributes.smile.value</th>\n",
       "      <th>attributes.smile.threshold</th>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7259aebcf1102e77d319afb93421b20a</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "      <td>Male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>99.995</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.059</td>\n",
       "      <td>42.294</td>\n",
       "      <td>52.431</td>\n",
       "      <td>4.920</td>\n",
       "      <td>0.179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6406687a3bddb21f8f578f71824bde69</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "      <td>Female</td>\n",
       "      <td>37.0</td>\n",
       "      <td>98.866</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.169</td>\n",
       "      <td>7.280</td>\n",
       "      <td>0.138</td>\n",
       "      <td>17.689</td>\n",
       "      <td>8.067</td>\n",
       "      <td>66.519</td>\n",
       "      <td>0.138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6bd9235ff544c5971a9f6ae32e6928e6</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "      <td>Male</td>\n",
       "      <td>23.0</td>\n",
       "      <td>100.000</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>99.996</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.002</td>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>fab96cc0c923e31011b2017d53874f81</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "      <td>Female</td>\n",
       "      <td>22.0</td>\n",
       "      <td>99.997</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "      <td>99.990</td>\n",
       "      <td>0.009</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3d51431ac7243d1bfdfd9ff72eb0dd30</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "      <td>Female</td>\n",
       "      <td>28.0</td>\n",
       "      <td>99.999</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.027</td>\n",
       "      <td>99.933</td>\n",
       "      <td>0.027</td>\n",
       "      <td>0.010</td>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e00fb75aac6cc7c5f6aa55b17bf8cd76</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  7259aebcf1102e77d319afb93421b20a                 123                  138   \n",
       "1  6406687a3bddb21f8f578f71824bde69                 122                  373   \n",
       "2  6bd9235ff544c5971a9f6ae32e6928e6                  46                  675   \n",
       "3  fab96cc0c923e31011b2017d53874f81                  98                  235   \n",
       "4  3d51431ac7243d1bfdfd9ff72eb0dd30                  75                  444   \n",
       "5  e00fb75aac6cc7c5f6aa55b17bf8cd76                  98                  537   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height attributes.gender.value  \\\n",
       "0                    90                     90                    Male   \n",
       "1                    65                     65                  Female   \n",
       "2                    54                     54                    Male   \n",
       "3                    53                     53                  Female   \n",
       "4                    52                     52                  Female   \n",
       "5                    48                     48                     NaN   \n",
       "\n",
       "   attributes.age.value  attributes.smile.value  attributes.smile.threshold  \\\n",
       "0                  23.0                  99.995                        50.0   \n",
       "1                  37.0                  98.866                        50.0   \n",
       "2                  23.0                 100.000                        50.0   \n",
       "3                  22.0                  99.997                        50.0   \n",
       "4                  28.0                  99.999                        50.0   \n",
       "5                   NaN                     NaN                         NaN   \n",
       "\n",
       "   attributes.emotion.anger  attributes.emotion.disgust  \\\n",
       "0                     0.059                       0.059   \n",
       "1                     0.169                       7.280   \n",
       "2                     0.000                       0.000   \n",
       "3                     0.000                       0.001   \n",
       "4                     0.001                       0.001   \n",
       "5                       NaN                         NaN   \n",
       "\n",
       "   attributes.emotion.fear  attributes.emotion.happiness  \\\n",
       "0                    0.059                        42.294   \n",
       "1                    0.138                        17.689   \n",
       "2                    0.000                        99.996   \n",
       "3                    0.000                        99.990   \n",
       "4                    0.027                        99.933   \n",
       "5                      NaN                           NaN   \n",
       "\n",
       "   attributes.emotion.neutral  attributes.emotion.sadness  \\\n",
       "0                      52.431                       4.920   \n",
       "1                       8.067                      66.519   \n",
       "2                       0.001                       0.002   \n",
       "3                       0.009                       0.000   \n",
       "4                       0.027                       0.010   \n",
       "5                         NaN                         NaN   \n",
       "\n",
       "   attributes.emotion.surprise  \n",
       "0                        0.179  \n",
       "1                        0.138  \n",
       "2                        0.001  \n",
       "3                        0.000  \n",
       "4                        0.001  \n",
       "5                          NaN  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <th>face_rectangle.height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7259aebcf1102e77d319afb93421b20a</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6406687a3bddb21f8f578f71824bde69</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6bd9235ff544c5971a9f6ae32e6928e6</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>fab96cc0c923e31011b2017d53874f81</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3d51431ac7243d1bfdfd9ff72eb0dd30</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e00fb75aac6cc7c5f6aa55b17bf8cd76</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  face_rectangle.top  face_rectangle.left  \\\n",
       "0  7259aebcf1102e77d319afb93421b20a                 123                  138   \n",
       "1  6406687a3bddb21f8f578f71824bde69                 122                  373   \n",
       "2  6bd9235ff544c5971a9f6ae32e6928e6                  46                  675   \n",
       "3  fab96cc0c923e31011b2017d53874f81                  98                  235   \n",
       "4  3d51431ac7243d1bfdfd9ff72eb0dd30                  75                  444   \n",
       "5  e00fb75aac6cc7c5f6aa55b17bf8cd76                  98                  537   \n",
       "\n",
       "   face_rectangle.width  face_rectangle.height  \n",
       "0                    90                     90  \n",
       "1                    65                     65  \n",
       "2                    54                     54  \n",
       "3                    53                     53  \n",
       "4                    52                     52  \n",
       "5                    48                     48  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_face_rectangle = df[['face_token','face_rectangle.top','face_rectangle.left','face_rectangle.width','face_rectangle.height']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  face_rectangle (pandas常规方法)\n",
    "* 先针对这变量看观察"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle</th>\n",
       "      <th>attributes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7259aebcf1102e77d319afb93421b20a</td>\n",
       "      <td>{'top': 123, 'left': 138, 'width': 90, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6406687a3bddb21f8f578f71824bde69</td>\n",
       "      <td>{'top': 122, 'left': 373, 'width': 65, 'height...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6bd9235ff544c5971a9f6ae32e6928e6</td>\n",
       "      <td>{'top': 46, 'left': 675, 'width': 54, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Male'}, 'age': {'value':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>fab96cc0c923e31011b2017d53874f81</td>\n",
       "      <td>{'top': 98, 'left': 235, 'width': 53, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3d51431ac7243d1bfdfd9ff72eb0dd30</td>\n",
       "      <td>{'top': 75, 'left': 444, 'width': 52, 'height'...</td>\n",
       "      <td>{'gender': {'value': 'Female'}, 'age': {'value...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e00fb75aac6cc7c5f6aa55b17bf8cd76</td>\n",
       "      <td>{'top': 98, 'left': 537, 'width': 48, 'height'...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         face_token  \\\n",
       "0  7259aebcf1102e77d319afb93421b20a   \n",
       "1  6406687a3bddb21f8f578f71824bde69   \n",
       "2  6bd9235ff544c5971a9f6ae32e6928e6   \n",
       "3  fab96cc0c923e31011b2017d53874f81   \n",
       "4  3d51431ac7243d1bfdfd9ff72eb0dd30   \n",
       "5  e00fb75aac6cc7c5f6aa55b17bf8cd76   \n",
       "\n",
       "                                      face_rectangle  \\\n",
       "0  {'top': 123, 'left': 138, 'width': 90, 'height...   \n",
       "1  {'top': 122, 'left': 373, 'width': 65, 'height...   \n",
       "2  {'top': 46, 'left': 675, 'width': 54, 'height'...   \n",
       "3  {'top': 98, 'left': 235, 'width': 53, 'height'...   \n",
       "4  {'top': 75, 'left': 444, 'width': 52, 'height'...   \n",
       "5  {'top': 98, 'left': 537, 'width': 48, 'height'...   \n",
       "\n",
       "                                          attributes  \n",
       "0  {'gender': {'value': 'Male'}, 'age': {'value':...  \n",
       "1  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "2  {'gender': {'value': 'Male'}, 'age': {'value':...  \n",
       "3  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "4  {'gender': {'value': 'Female'}, 'age': {'value...  \n",
       "5                                                NaN  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 立马试试pd.DataFrame 並观察\n",
    "faces_data = results['faces']\n",
    "df = pd.DataFrame(faces_data)\n",
    "df\n",
    "\n",
    "# attributes, face_rectangle, face_token\n",
    "# 查一下API文檔"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'top': 123, 'left': 138, 'width': 90, 'height...\n",
       "1    {'top': 122, 'left': 373, 'width': 65, 'height...\n",
       "2    {'top': 46, 'left': 675, 'width': 54, 'height'...\n",
       "3    {'top': 98, 'left': 235, 'width': 53, 'height'...\n",
       "4    {'top': 75, 'left': 444, 'width': 52, 'height'...\n",
       "5    {'top': 98, 'left': 537, 'width': 48, 'height'...\n",
       "Name: face_rectangle, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取变量 (pandas cheetsheet)\n",
    "df[\"face_rectangle\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: {'top': 123, 'left': 138, 'width': 90, 'height': 90},\n",
       " 1: {'top': 122, 'left': 373, 'width': 65, 'height': 65},\n",
       " 2: {'top': 46, 'left': 675, 'width': 54, 'height': 54},\n",
       " 3: {'top': 98, 'left': 235, 'width': 53, 'height': 53},\n",
       " 4: {'top': 75, 'left': 444, 'width': 52, 'height': 52},\n",
       " 5: {'top': 98, 'left': 537, 'width': 48, 'height': 48}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"face_rectangle\"].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>123</td>\n",
       "      <td>122</td>\n",
       "      <td>46</td>\n",
       "      <td>98</td>\n",
       "      <td>75</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>left</th>\n",
       "      <td>138</td>\n",
       "      <td>373</td>\n",
       "      <td>675</td>\n",
       "      <td>235</td>\n",
       "      <td>444</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>width</th>\n",
       "      <td>90</td>\n",
       "      <td>65</td>\n",
       "      <td>54</td>\n",
       "      <td>53</td>\n",
       "      <td>52</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>height</th>\n",
       "      <td>90</td>\n",
       "      <td>65</td>\n",
       "      <td>54</td>\n",
       "      <td>53</td>\n",
       "      <td>52</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0    1    2    3    4    5\n",
       "top     123  122   46   98   75   98\n",
       "left    138  373  675  235  444  537\n",
       "width    90   65   54   53   52   48\n",
       "height   90   65   54   53   52   48"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"face_rectangle\"].to_dict())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>top</th>\n",
       "      <th>left</th>\n",
       "      <th>width</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   top  left  width  height\n",
       "0  123   138     90      90\n",
       "1  122   373     65      65\n",
       "2   46   675     54      54\n",
       "3   98   235     53      53\n",
       "4   75   444     52      52\n",
       "5   98   537     48      48"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(df[\"face_rectangle\"].to_dict()).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>face_rectangle_top</th>\n",
       "      <th>face_rectangle_left</th>\n",
       "      <th>face_rectangle_width</th>\n",
       "      <th>face_rectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   face_rectangle_top  face_rectangle_left  face_rectangle_width  \\\n",
       "0                 123                  138                    90   \n",
       "1                 122                  373                    65   \n",
       "2                  46                  675                    54   \n",
       "3                  98                  235                    53   \n",
       "4                  75                  444                    52   \n",
       "5                  98                  537                    48   \n",
       "\n",
       "   face_rectangle_height  \n",
       "0                     90  \n",
       "1                     65  \n",
       "2                     54  \n",
       "3                     53  \n",
       "4                     52  \n",
       "5                     48  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_rect = pd.DataFrame(df[\"face_rectangle\"].to_dict()).T\n",
    "# 欄位名稱加上 face_rectangle \n",
    "df_rect.columns = [ \"face_rectangle_\"+x for x in df_rect.columns]\n",
    "df_rect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>attributes</th>\n",
       "      <th>face_rectangle</th>\n",
       "      <th>face_token</th>\n",
       "      <th>face_rectangle_width</th>\n",
       "      <th>face_rectangle_top</th>\n",
       "      <th>face_rectangle_left</th>\n",
       "      <th>face_rectangle_height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{'emotion': {'sadness': 4.92, 'neutral': 52.43...</td>\n",
       "      <td>{'width': 90, 'top': 123, 'left': 138, 'height...</td>\n",
       "      <td>5deb72f15e0af9c1c802b34e3752ff58</td>\n",
       "      <td>90</td>\n",
       "      <td>123</td>\n",
       "      <td>138</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{'emotion': {'sadness': 66.519, 'neutral': 8.0...</td>\n",
       "      <td>{'width': 65, 'top': 122, 'left': 373, 'height...</td>\n",
       "      <td>468ae7d534c0aa63a00566d1ac1d82f4</td>\n",
       "      <td>65</td>\n",
       "      <td>122</td>\n",
       "      <td>373</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{'emotion': {'sadness': 0.002, 'neutral': 0.00...</td>\n",
       "      <td>{'width': 54, 'top': 46, 'left': 675, 'height'...</td>\n",
       "      <td>2f22e764e77a43961e415b9579269901</td>\n",
       "      <td>54</td>\n",
       "      <td>46</td>\n",
       "      <td>675</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{'emotion': {'sadness': 0.0, 'neutral': 0.009,...</td>\n",
       "      <td>{'width': 53, 'top': 98, 'left': 235, 'height'...</td>\n",
       "      <td>19e3ecc4f3da6ed62c58f7f20b4653e5</td>\n",
       "      <td>53</td>\n",
       "      <td>98</td>\n",
       "      <td>235</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{'emotion': {'sadness': 0.01, 'neutral': 0.027...</td>\n",
       "      <td>{'width': 52, 'top': 75, 'left': 444, 'height'...</td>\n",
       "      <td>67ad68260072391c47dcd72fc62c73e5</td>\n",
       "      <td>52</td>\n",
       "      <td>75</td>\n",
       "      <td>444</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>NaN</td>\n",
       "      <td>{'width': 48, 'top': 98, 'left': 537, 'height'...</td>\n",
       "      <td>0788086a4f4079f14514ff10f0dab526</td>\n",
       "      <td>48</td>\n",
       "      <td>98</td>\n",
       "      <td>537</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          attributes  \\\n",
       "0  {'emotion': {'sadness': 4.92, 'neutral': 52.43...   \n",
       "1  {'emotion': {'sadness': 66.519, 'neutral': 8.0...   \n",
       "2  {'emotion': {'sadness': 0.002, 'neutral': 0.00...   \n",
       "3  {'emotion': {'sadness': 0.0, 'neutral': 0.009,...   \n",
       "4  {'emotion': {'sadness': 0.01, 'neutral': 0.027...   \n",
       "5                                                NaN   \n",
       "\n",
       "                                      face_rectangle  \\\n",
       "0  {'width': 90, 'top': 123, 'left': 138, 'height...   \n",
       "1  {'width': 65, 'top': 122, 'left': 373, 'height...   \n",
       "2  {'width': 54, 'top': 46, 'left': 675, 'height'...   \n",
       "3  {'width': 53, 'top': 98, 'left': 235, 'height'...   \n",
       "4  {'width': 52, 'top': 75, 'left': 444, 'height'...   \n",
       "5  {'width': 48, 'top': 98, 'left': 537, 'height'...   \n",
       "\n",
       "                         face_token  face_rectangle_width  face_rectangle_top  \\\n",
       "0  5deb72f15e0af9c1c802b34e3752ff58                    90                 123   \n",
       "1  468ae7d534c0aa63a00566d1ac1d82f4                    65                 122   \n",
       "2  2f22e764e77a43961e415b9579269901                    54                  46   \n",
       "3  19e3ecc4f3da6ed62c58f7f20b4653e5                    53                  98   \n",
       "4  67ad68260072391c47dcd72fc62c73e5                    52                  75   \n",
       "5  0788086a4f4079f14514ff10f0dab526                    48                  98   \n",
       "\n",
       "   face_rectangle_left  face_rectangle_height  \n",
       "0                  138                     90  \n",
       "1                  373                     65  \n",
       "2                  675                     54  \n",
       "3                  235                     53  \n",
       "4                  444                     52  \n",
       "5                  537                     48  "
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用.join合併\n",
    "df.join(df_rect)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  face_rectangle\n",
    "* 該你了\n",
    "* 如何類似手法，運用你pandas的知識，抽出 attributes的數據\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "1    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "2    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "3    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "4    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "5                                                  NaN\n",
       "Name: attributes, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"attributes\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'anger': 0.001,\n",
       " 'disgust': 0.001,\n",
       " 'fear': 0.027,\n",
       " 'happiness': 99.933,\n",
       " 'neutral': 0.027,\n",
       " 'sadness': 0.01,\n",
       " 'surprise': 0.001}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"attributes\"].loc[4]['emotion']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df[\"attributes\"].loc[0]['emotion'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'float' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-16-af72a7c61d0b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"attributes\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'emotion'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'float' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "df[\"attributes\"].loc[5]['emotion']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "1    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "2    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "3    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "4    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "5                                                  NaN\n",
       "Name: attributes, dtype: object"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np  # missing value np.nan\n",
    "missing_value = {\"emotion\": {'sadness': np.nan, 'neutral': np.nan, 'disgust': np.nan, 'anger': np.nan, 'surprise': np.nan, 'fear': np.nan, 'happiness': np.nan}}\n",
    "df[\"attributes\"] = df[\"attributes\"].fillna(missing_value)\n",
    "df[\"attributes\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "1    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "2    {'gender': {'value': 'Male'}, 'age': {'value':...\n",
       "3    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "4    {'gender': {'value': 'Female'}, 'age': {'value...\n",
       "5                                                     \n",
       "Name: attributes, dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"attributes\"].fillna(\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 {'anger': 0.059, 'disgust': 0.059, 'fear': 0.059, 'happiness': 42.275, 'neutral': 52.466, 'sadness': 4.903, 'surprise': 0.179}\n",
      "1 {'anger': 0.169, 'disgust': 7.346, 'fear': 0.137, 'happiness': 17.673, 'neutral': 8.043, 'sadness': 66.494, 'surprise': 0.137}\n",
      "2 {'anger': 0.0, 'disgust': 0.0, 'fear': 0.0, 'happiness': 99.996, 'neutral': 0.001, 'sadness': 0.002, 'surprise': 0.001}\n",
      "3 {'anger': 0.0, 'disgust': 0.001, 'fear': 0.0, 'happiness': 99.99, 'neutral': 0.009, 'sadness': 0.0, 'surprise': 0.0}\n",
      "4 {'anger': 0.001, 'disgust': 0.001, 'fear': 0.027, 'happiness': 99.933, 'neutral': 0.027, 'sadness': 0.01, 'surprise': 0.001}\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'float' object has no attribute 'get'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-20-fd62967a3348>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"attributes\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m     \u001b[0;31m# print (i,df[\"attributes\"].loc[i][\"emotion\"])\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m     \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"attributes\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"emotion\"\u001b[0m\u001b[0;34m)\u001b[0m  \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'float' object has no attribute 'get'"
     ]
    }
   ],
   "source": [
    "for i in df[\"attributes\"].index:\n",
    "    # print (i,df[\"attributes\"].loc[i][\"emotion\"])\n",
    "    print (i,df[\"attributes\"].loc[i].get(\"emotion\")  )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df[\"attributes\"].loc[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'sadness': 4.92,\n",
       "  'neutral': 52.431,\n",
       "  'disgust': 0.059,\n",
       "  'anger': 0.059,\n",
       "  'surprise': 0.179,\n",
       "  'fear': 0.059,\n",
       "  'happiness': 42.294},\n",
       " {'sadness': 66.519,\n",
       "  'neutral': 8.067,\n",
       "  'disgust': 7.28,\n",
       "  'anger': 0.169,\n",
       "  'surprise': 0.138,\n",
       "  'fear': 0.138,\n",
       "  'happiness': 17.689},\n",
       " {'sadness': 0.002,\n",
       "  'neutral': 0.001,\n",
       "  'disgust': 0.0,\n",
       "  'anger': 0.0,\n",
       "  'surprise': 0.001,\n",
       "  'fear': 0.0,\n",
       "  'happiness': 99.996},\n",
       " {'sadness': 0.0,\n",
       "  'neutral': 0.009,\n",
       "  'disgust': 0.001,\n",
       "  'anger': 0.0,\n",
       "  'surprise': 0.0,\n",
       "  'fear': 0.0,\n",
       "  'happiness': 99.99},\n",
       " {'sadness': 0.01,\n",
       "  'neutral': 0.027,\n",
       "  'disgust': 0.001,\n",
       "  'anger': 0.001,\n",
       "  'surprise': 0.001,\n",
       "  'fear': 0.027,\n",
       "  'happiness': 99.933},\n",
       " {'emotion': {'sadness': nan,\n",
       "   'neutral': nan,\n",
       "   'disgust': nan,\n",
       "   'anger': nan,\n",
       "   'surprise': nan,\n",
       "   'fear': nan,\n",
       "   'happiness': nan}}]"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[df[\"attributes\"].loc[i][\"emotion\"] if type(df[\"attributes\"].loc[i])  is dict else missing_value for i in df[\"attributes\"].index ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>attributes_emotion_sadness</th>\n",
       "      <th>attributes_emotion_neutral</th>\n",
       "      <th>attributes_emotion_disgust</th>\n",
       "      <th>attributes_emotion_anger</th>\n",
       "      <th>attributes_emotion_surprise</th>\n",
       "      <th>attributes_emotion_fear</th>\n",
       "      <th>attributes_emotion_happiness</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4.920</td>\n",
       "      <td>52.431</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.059</td>\n",
       "      <td>0.179</td>\n",
       "      <td>0.059</td>\n",
       "      <td>42.294</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>66.519</td>\n",
       "      <td>8.067</td>\n",
       "      <td>7.280</td>\n",
       "      <td>0.169</td>\n",
       "      <td>0.138</td>\n",
       "      <td>0.138</td>\n",
       "      <td>17.689</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.002</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "      <td>99.996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000</td>\n",
       "      <td>0.009</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>99.990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.010</td>\n",
       "      <td>0.027</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.001</td>\n",
       "      <td>0.027</td>\n",
       "      <td>99.933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   attributes_emotion_sadness  attributes_emotion_neutral  \\\n",
       "0                       4.920                      52.431   \n",
       "1                      66.519                       8.067   \n",
       "2                       0.002                       0.001   \n",
       "3                       0.000                       0.009   \n",
       "4                       0.010                       0.027   \n",
       "5                         NaN                         NaN   \n",
       "\n",
       "   attributes_emotion_disgust  attributes_emotion_anger  \\\n",
       "0                       0.059                     0.059   \n",
       "1                       7.280                     0.169   \n",
       "2                       0.000                     0.000   \n",
       "3                       0.001                     0.000   \n",
       "4                       0.001                     0.001   \n",
       "5                         NaN                       NaN   \n",
       "\n",
       "   attributes_emotion_surprise  attributes_emotion_fear  \\\n",
       "0                        0.179                    0.059   \n",
       "1                        0.138                    0.138   \n",
       "2                        0.001                    0.000   \n",
       "3                        0.000                    0.000   \n",
       "4                        0.001                    0.027   \n",
       "5                          NaN                      NaN   \n",
       "\n",
       "   attributes_emotion_happiness  \n",
       "0                        42.294  \n",
       "1                        17.689  \n",
       "2                        99.996  \n",
       "3                        99.990  \n",
       "4                        99.933  \n",
       "5                           NaN  "
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_attr_emotion = pd.DataFrame([df[\"attributes\"].loc[i][\"emotion\"] if type(df[\"attributes\"].loc[i])  is dict else missing_value['emotion'] for i in df[\"attributes\"].index ])\n",
    "# 欄位名稱加上 face_rectangle \n",
    "df_attr_emotion.columns = [ \"attributes_emotion_\"+x for x in df_attr_emotion.columns]\n",
    "df_attr_emotion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
